package com.wits.qso.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wits.platform.common.utils.FileUtil;
import com.wits.platform.common.utils.PageUtil;
import com.wits.platform.web.controller.BaseController;
import com.wits.qso.entity.Attachment;
import com.wits.qso.service.AttachmentService;

@Controller
@RequestMapping(value = "/qso/attachment")
public class AttachmentController extends BaseController {

	
	@Autowired
	private AttachmentService attachmentService;
	

	
	@RequestMapping(value = "/getAttachment")
	@ResponseBody
	public String getAttachment(@RequestParam("bId") String bId,@RequestParam("bType") String bType) {
		
		List<Attachment> list=attachmentService.findByBusiness(bId,bType);
	
		return PageUtil.toAjaxPageResult(list);
	}
	
	@RequestMapping(value = "/downLoad/{id}")
	public void downLoad(HttpServletRequest req,HttpServletResponse res,@PathVariable("id") String id){
		String basePath = req.getSession().getServletContext().getRealPath("/");
		Attachment att=attachmentService.getOne(id);
		String contentType = "application/octet-stream";
		FileUtil.download(res,basePath,contentType,att);
	}
}
